package com.das.mechanic_base.widget;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.adapter.groundpush.X3ServiceCarInfoAdapter;
import com.das.mechanic_base.base.X3BaseBottomSheetDialog;
import com.das.mechanic_base.bean.ground.UserCarInfoBean;
import com.das.mechanic_base.bean.main.AppointClueBean;
import com.umeng.analytics.MobclickAgent;

import java.util.List;

public class X3BottomServiceAppointDialog extends X3BaseBottomSheetDialog implements View.OnClickListener, X3ServiceCarInfoAdapter.IOnClickCar {

    private TextView tv_cancel;
    private RecyclerView rlv_car;
    private Button btn_sure;
    private X3ServiceCarInfoAdapter carInfoAdapter;

    private AppointClueBean clueBean;
    private long carOwnId;

    public X3BottomServiceAppointDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean getDialogCancel() {
        return false;
    }

    @Override
    protected void initView() {
        tv_cancel = getView(R.id.tv_cancel);
        btn_sure = getView(R.id.btn_sure);
        rlv_car = getView(R.id.rlv_car);

        rlv_car.setLayoutManager(new LinearLayoutManager(mContext));
        tv_cancel.setOnClickListener(this);
        btn_sure.setOnClickListener(this);

        clueBean = new AppointClueBean();

        carInfoAdapter = new X3ServiceCarInfoAdapter(mContext);
        rlv_car.setAdapter(carInfoAdapter);
        carInfoAdapter.setiOnClickCar(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.x3_appoint_service_bottom_dialog;
    }

    @Override
    public void show() {
        super.show();
        btn_sure.setBackgroundColor(Color.parseColor("#D5D5D5"));
        btn_sure.setEnabled(false);
    }

    public void setCarInfo(List<UserCarInfoBean> carInfo,long carOwnerId) {
        carOwnId = carOwnerId;
        if (carInfoAdapter != null) {
            carInfoAdapter.changeGroup(carInfo);
        }
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tv_cancel) {
            dismiss();
        } else if (id == R.id.btn_sure) {// 下一步
            if (iOnClickSelect != null) {
                iOnClickSelect.iOnClickSelectCar(clueBean);
            }
        }
    }

    IOnClickSelect iOnClickSelect;

    public void setiOnClickSelect(IOnClickSelect iOnClickSelect) {
        this.iOnClickSelect = iOnClickSelect;
    }

    public interface IOnClickSelect {
        void iOnClickSelectCar(AppointClueBean clueBean);
    }

    @Override
    public void iOnClickCarNext(long brandId, long carStyleId, long carId, String carStyle) {
        clueBean.setCarBrandId(brandId);
        clueBean.setCarStyleId(carStyleId);
        clueBean.setCarId(carId);
        clueBean.setCarStyleName(carStyle);
        clueBean.setCarOwnerUserId(carOwnId);

        btn_sure.setBackgroundColor(Color.parseColor("#0077ff"));
        btn_sure.setEnabled(true);

    }
    @Override
    protected void onStart() {
        super.onStart();
        MobclickAgent.onPageStart("服务预约弹窗");
    }

    @Override
    protected void onStop() {
        super.onStop();
        MobclickAgent.onPageEnd("服务预约弹窗");
    }
}
